Wrap calls to time(2) so we can freeze time for test suite.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 7 Apr 2004 15:13:17 +0000 (15:13 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 7 Apr 2004 15:13:17 +0000 (15:13 +0000)
21 files changed:
gpsbabel/Makefile
gpsbabel/cetus.c
gpsbabel/copilot.c
gpsbabel/defs.h
gpsbabel/gcdb.c
gpsbabel/geoniche.c
gpsbabel/gpilots.c
gpsbabel/gpsdrive.c
gpsbabel/gpspilot.c
gpsbabel/gpsutil.c
gpsbabel/gpx.c
gpsbabel/magnav.c
gpsbabel/magproto.c
gpsbabel/mapopolis.c
gpsbabel/mapsource.c
gpsbabel/nmea.c
gpsbabel/pcx.c
gpsbabel/psitrex.c
gpsbabel/quovadis.c
gpsbabel/tiger.c
gpsbabel/util.c

index 97976c4ce7ef434f4351a62542be2343c0d90d4c..e41dbd80cbbb75e5b2488ff0d8c084b6385a4db4 100644 (file)
@@ -78,10 +78,10 @@ dep:
        (echo -n "internal_styles.c: mkstyle.sh " ; echo style/*.style ; /bin/echo -e '\t./mkstyle.sh > $@ || (rm -f $@ ; exit 1)' ) >> /tmp/dep
        echo Edit Makefile and bring in /tmp/dep
 
-VERSIONU=1_2_2_beta0317a2004
-VERSIOND=1.2.2_beta0317a2004
-VERSIONU=1_2_2
-VERSIOND=1.2.2
+VERSIONU=1_2_3_beta04052004
+VERSIOND=1.2.3_beta04052004
+#VERSIONU=1_2_2
+#VERSIOND=1.2.2
 
 release:
        cvs commit
index 170dd8bf996033e9bb50935af05dcab1b2881a42..fd17a0918505f94610c8b624d97a9d45346c9b27 100644 (file)
@@ -378,7 +378,7 @@ data_write(void)
        }
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
        opdb->type = MYTYPE;  /* CWpt */
        opdb->creator = MYCREATOR; /* cGPS */
        opdb->version = 1;
index 44a55e0cb02df58a06535199ca84c27b79ad6370..10d028da44f7398e3ea86a223654aefe774c9d60 100644 (file)
@@ -180,7 +180,7 @@ data_write(void)
        strncpy(opdb->name, out_fname, PDB_DBNAMELEN);
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
        opdb->type = MYTYPE;
        opdb->creator = MYCREATOR; 
        opdb->version = 0;
index bed5562426c87bb2deea5e2b0f39e5df846bbacd..4c23177236abdf4d286c0970ead45ecc4351e7ed 100644 (file)
@@ -410,6 +410,7 @@ int case_ignore_strcmp(const char *s1, const char *s2);
 char *strsub(char *s, char *search, char *replace);
 void rtrim(char *s);
 signed int get_tz_offset(void);
+time_t current_time(void);
 signed int month_lookup(const char *m);
 const char *get_cache_icon(const waypoint *waypointp);
 char * xml_entitize(const char * str);
index b4bd3ac52b29164daa40d1517f6327a92bbe2a52..84e5725ce2a284301a6eb4718e4ffbb72b14f366 100644 (file)
@@ -318,7 +318,7 @@ data_write(void)
        strncpy(opdb->name, "GeocachingDB", PDB_DBNAMELEN);
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
        opdb->type = MYTYPE;  /* CWpt */
        opdb->creator = MYCREATOR; /* cGPS */
        opdb->version = 1;
index 12aac56bb51df43709affc64b497096919384ea8..4302ff2799fd35438bff190cdaad92f3782d935c 100644 (file)
@@ -509,7 +509,7 @@ data_write(void)
     PdbOut->name[PDB_DBNAMELEN-1] = 0;
 
     PdbOut->attributes = PDB_ATTR_BACKUP;
-    PdbOut->ctime = PdbOut->mtime = time(NULL) + (49*365 + 17*366) * (60*60*24);
+    PdbOut->ctime = PdbOut->mtime = current_time() + (49*365 + 17*366) * (60*60*24);
     PdbOut->type = MYTYPE;
     PdbOut->creator = MYCREATOR; 
     PdbOut->version = 0;
index b615fde997c7339aa03019f648434151fa2df42c..fb8f6f1a74b1e81f6649816b0a6ee1ae595d195d 100644 (file)
@@ -291,7 +291,7 @@ data_write(void)
         */
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
 
        opdb->type = MYWPT;
        opdb->creator = MYCREATOR;
index 51bd73d15e8f626698bdd4abe035bf56c6bef9c5..621fa497643a8ec23191a46ed6f3a889ea8f0f76 100644 (file)
@@ -76,7 +76,7 @@ data_read(void)
         * Make sure that all waypoints in single read have same 
         * timestamp.
         */
-       time_t now = time(NULL);
+       time_t now = current_time();
 
        do {
                linecount++;
index 36f4ec0715f1515580ec88cb56d934415cb879fb..5edc2151328a4b8ae9632974c6a2bf98471fe246 100644 (file)
@@ -234,7 +234,7 @@ data_write(void)
        }
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
        opdb->type = MYTYPE_POINTS;
        opdb->creator = MYCREATOR; 
        opdb->version = 0;
index c8d5ae85aabcb35276db68b3f165ab0d6faf50d2..2ab25528c33b58eaf65d7f4e04e69bbdf2da8c36 100644 (file)
@@ -53,7 +53,7 @@ data_read(void)
         * Make sure that all waypoints in single read have same 
         * timestamp.
         */
-       time_t now = time(NULL);
+       time_t now = current_time();
 
 
        for(;fgets(ibuf, sizeof(ibuf), file_in);) {
index ff111654b8237e711321cd498fbe53bbba8f07cb..95ea894bc0abab48d3ddae91586a4dee500df66f 100644 (file)
@@ -1197,7 +1197,7 @@ gpx_write(void)
        int short_length;
        bounds bounds;
        
-        time( &now );
+        now = current_time();
 
        if (snlen)
                short_length = atoi(snlen);
index e8483743704a0d13554f046604c420099f8dc56f..392974e40e22797d582a2434a3f9c6dd5e948ca8 100644 (file)
@@ -155,7 +155,7 @@ my_writewpt(const waypoint *wpt)
                tm = gmtime( &wpt->creation_time);
        }
        if ( !tm ) {
-               time( &tm_t );
+               tm_t = current_time();
                tm = gmtime( &tm_t );
        }
        
@@ -248,7 +248,7 @@ data_write(void)
        strncpy(opdb->name, "Companion Waypoints", PDB_DBNAMELEN);
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
        opdb->type = MYTYPE;  /* CWpt */
        opdb->creator = MYCREATOR; /* cGPS */
        opdb->version = 1;
index e84705621809efc44f7bc310a15fd63dd8913dd2..b0f66d8a1735171273d8d4c8b22772adb993e206 100644 (file)
@@ -720,7 +720,7 @@ mag_rd_init(const char *portname)
        if (!noack)
                mag_handon();
 
-       now = time(NULL);
+       now = current_time();
        /*
         * The 315 can take up to 4.25 seconds to respond to initialization
         * commands.   Time out on the side of caution.
@@ -733,7 +733,7 @@ mag_rd_init(const char *portname)
 
        while (!got_version) {
                mag_readmsg();
-               if (time(NULL) > later) {
+               if (current_time() > later) {
                        fatal(MYNAME ": No acknowledgment from GPS on %s\n",
                                portname);
                }
index ebc8bd83f7b2561ff857e89963a8cd84eaafe0b1..fecb23f871c1a8ce0a8e2d8ec264fb12d09bf690 100644 (file)
@@ -200,7 +200,7 @@ my_writewpt(const waypoint *wpt)
                tm = gmtime( &wpt->creation_time);
        }
        if ( !tm ) {
-               time( &tm_t );
+               tm_t = current_time();
                tm = gmtime( &tm_t );
        }
        
@@ -296,7 +296,7 @@ data_write(void)
        strncpy(opdb->name, "Companion Waypoints", PDB_DBNAMELEN);
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
        opdb->type = MYTYPE;  /* CWpt */
        opdb->creator = MYCREATOR; /* cGPS */
        opdb->version = 1;
index eab8b5e91b94f02bd420d4f3430be385792e6e54..a22647c27a0c31f676060752e1afdfd00be3d04b 100644 (file)
@@ -251,7 +251,7 @@ mps_wr_init(const char *fname)
                }
                else {
                        fclose(mps_file_out);
-                       srand((unsigned) time(NULL));
+                       srand((unsigned) current_time());
 
                        for (;;) {
                                /* create a temporary name  based on a random char and the existing name */
@@ -1143,7 +1143,7 @@ mps_routehdr_w(FILE *mps_file, int mps_ver, const route_head *rte)
                }               
 
                if (uniqueValue == 0) {
-                       uniqueValue = time(NULL);
+                       uniqueValue = current_time();
                }
 
                /* route name */
@@ -1562,7 +1562,7 @@ mps_trackhdr_w(FILE *mps_file, int mps_ver, const route_head *trk)
                }
 
                if (uniqueValue == 0) {
-                       uniqueValue = time(NULL);
+                       uniqueValue = current_time();
                }
 
                /* track name */
index 2fc81221eb0b02497653b0cad1998640c6ff7f43..34c39da3ef3be1f024b413c5368111f7aaf91d74 100644 (file)
@@ -152,7 +152,7 @@ gpgll_parse(char *ibuf)
        hms = hms / 100;
        tm.tm_hour = hms % 100;
 
-       waypt->creation_time = mktime(&tm) + get_tz_offset() + time(0);
+       waypt->creation_time = mktime(&tm) + get_tz_offset() + current_time();
 
        if (latdir == 'S') latdeg = -latdeg;
        waypt->latitude = ddmm2degrees(latdeg);
@@ -197,7 +197,7 @@ gpgga_parse(char *ibuf)
        hms = hms / 100;
        tm.tm_hour = (long) hms % 100;
 
-       waypt->creation_time = mktime(&tm) + get_tz_offset() + time(NULL);
+       waypt->creation_time = mktime(&tm) + get_tz_offset() + current_time();
 
        if (latdir == 'S') latdeg = -latdeg;
        waypt->latitude = ddmm2degrees(latdeg);
index 07b4d95669d7d10ccde8d7d9a5d7fe0cddfbaacf..cba08c71d680ac554a028a74373ff3a643218419 100644 (file)
@@ -146,7 +146,7 @@ gpsutil_disp(const waypoint *wpt)
        lat = degrees2ddmm(wpt->latitude);
 
        if (tm == 0) 
-               tm = time(NULL);
+               tm = current_time();
        strftime(tbuf, sizeof(tbuf), "%d-%b-%y %I:%M:%S", localtime(&tm));
        while (*tp) {
                *tp = toupper(*tp);
index fe55b6c5ed297eee8b6e1d5291ffd9509dd04c77..f23aea6115a527d721db2db1c99e73c6f88f5854 100755 (executable)
@@ -483,7 +483,7 @@ psit_routehdr_w(FILE *psit_file, const route_head *rte)
                }               
 
                if (uniqueValue == 0) {
-                       uniqueValue = time(NULL);
+                       uniqueValue = current_time();
                }
 
                /* route name */
@@ -638,7 +638,7 @@ psit_trackhdr_w(FILE *psit_file, const route_head *trk)
                        }
 
                        if (uniqueValue == 0) {
-                               uniqueValue = time(NULL);
+                               uniqueValue = current_time();
                        }
 
                        /* track name */
index bf8796d3da0ac5c5668cc81618ddef8c68c59179..7300f59715539daa95e51f1acadce23f6a801701 100644 (file)
@@ -238,7 +238,7 @@ data_write(void)
        }
        opdb->name[PDB_DBNAMELEN-1] = 0;
        opdb->attributes = PDB_ATTR_BACKUP;
-       opdb->ctime = opdb->mtime = time(NULL) + 2082844800U;
+       opdb->ctime = opdb->mtime = current_time() + 2082844800U;
        opdb->type = MYTYPE;  /* CWpt */
        opdb->creator = MYCREATOR; /* cGPS */
        opdb->version = 1;
index 312fa0e7def4571c84c22559066566d696e713c7..a850588e3316341c0f72f3e59a4b3d53c5ac2746 100644 (file)
@@ -155,7 +155,7 @@ tiger_disp(const waypoint *wpt)
                pin = wpt->icon_descr ? wpt->icon_descr : "";
        else if (wpt->icon_descr && strstr(wpt->icon_descr, "-unfound"))
                pin = unfoundmarker;
-       else if (wpt->creation_time > time(0) - 3600 * 24 * thresh_days)
+       else if (wpt->creation_time > current_time() - 3600 * 24 * thresh_days)
                pin = newmarker;
        else
                pin = oldmarker;
index e16b53821e35d30070a1278f72a37b424b9303d2..8e19674419696c725e22e5d34dbf8ff819ee7ef7 100644 (file)
@@ -447,7 +447,7 @@ si_round( double d )
 signed int 
 get_tz_offset(void)
 {
-       time_t now = time(0);
+       time_t now = current_time();
        time_t later = mktime(gmtime(&now));
 
        if (later == -1) {
@@ -457,6 +457,21 @@ get_tz_offset(void)
        }
 }
 
+/*
+ * A wrapper for time(2) that allows us to "freeze" time for testing.
+ */
+time_t
+current_time(void)
+{
+       static char *frozen;
+       
+       if (getenv("GPSBABEL_FREEZE_TIME")) {
+               return 0;
+       }
+
+       return time(NULL);
+}
+
 /*
  * Return the (zero based) month number of the year or -1 for failure.
  */